package com.canaan.web.controller.monitor;

import java.util.List;

import com.canaan.system.domain.ApiLog;
import com.canaan.system.service.IApiLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.enums.BusinessType;
import javax.annotation.Resource;
import com.canaan.common.utils.poi.ExcelUtil;
import com.canaan.common.core.page.TableDataInfo;

/**
 * Api日志记录Controller
 *
 * @author canaan
 * @date 2025-03-23
 */
@Api(tags = "Api日志记录")
@RestController
@RequestMapping("/monitor/apilog")
public class ApiLogController extends BaseController {
    @Resource
    private IApiLogService apiLogService;

    /**
     * 查询Api日志记录列表
     */
    @ApiOperation(value = "查询Api日志记录列表")
    @PreAuthorize("@ss.hasPermi('monitor:apilog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApiLog apiLog) {
        startPage();
        List<ApiLog> list = apiLogService.selectApiLogList(apiLog);
        return getDataTable(list);
    }

    /**
     * 导出Api日志记录列表
     */
    @ApiOperation(value = "导出Api日志记录列表")
    @PreAuthorize("@ss.hasPermi('monitor:apilog:export')")
    @Log(title = "Api日志记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApiLog apiLog) {
        List<ApiLog> list = apiLogService.selectApiLogList(apiLog);
        ExcelUtil<ApiLog> util = new ExcelUtil<ApiLog>(ApiLog.class);
        util.exportExcel(response, list, "Api日志记录数据");
    }

    /**
     * 获取Api日志记录详细信息
     */
    @ApiOperation(value = "获取Api日志记录详细信息")
    @PreAuthorize("@ss.hasPermi('monitor:apilog:query')")
    @GetMapping(value = "/{operId}")
    public AjaxResult getInfo(@PathVariable("operId") Long operId) {
        return success(apiLogService.selectApiLogByLogId(operId));
    }

}
